package com.oocl.customer.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



import com.oocl.customersystem.dto.MUser;
import com.oocl.customersystem.dto.MUserFoodList;
import com.oocl.customersystem.util.RequestUtil;

/**
 * Servlet implementation class ShowFoodByType
 */
public class ShowFoodByType extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShowFoodByType() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	@SuppressWarnings("unchecked")
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String uri1="http://ZHA-ITA092-W7:8089/merchantv2/foodlist2c";
		String uri2 = "http://ZHA-ITA092-W7:8089/merchantv2/muserslist2C";
		
		String mId=request.getParameter("mid");
//		String mId="123456789012345678";
		String fType=request.getParameter("ftype");
		String vegOrmer = request.getParameter("vegOrmer");
//		String vegOrmer ="1";
		String par="mid="+mId+"&ftype="+fType;
		MUserFoodList dto= null;
		if("1".equals(vegOrmer)){
			dto=(MUserFoodList)RequestUtil.request(uri1, "POST", par, MUserFoodList.class);
			System.out.println(dto);
			request.setAttribute("mufl", dto);	
			request.setAttribute("ftype", fType);
			request.getRequestDispatcher("showFoodByMerchant.jsp").forward(request, response);
		}else if("0".equals(vegOrmer)){
			par = "type="+ fType;
			System.out.println(par);
			List<MUser> list=(List<MUser>)RequestUtil.request(uri2, "POST", par, List.class);
			request.setAttribute("mlist", list);	
			request.setAttribute("ftype", fType);
			request.getRequestDispatcher("showMerchant.jsp").forward(request, response);
		}
		
		System.out.println(fType);
		

		
		
	}

}
